package com.gohome.gohomechat.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by dllo on 16/2/29.
 */
public abstract class BaseFragment extends Fragment{
    private View view;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(getLayout(),container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        this.view=view;
        initView(view);
    }



        @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
        initPresenter();
        initData();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * 简化findViewById
     * @param id
     * @param <T>
     * @return
     */
    protected <T extends View> T findView(int id){
        T t = (T)view.findViewById(id);
        return t;
    }

    /**
     * 返回布局文件的地址
     * @return
     */
    protected abstract int getLayout();

    /**
     * 初始化Presenter
     */
    protected abstract void initPresenter();

    /**
     * 初始化控件
     */
    protected abstract void initView(View view);

    /**
     * 数据的操作
     */
    protected abstract void initData();

}
